﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using FMOD;

namespace _3Dsoundor2Dgraphor.Sound
{
	class SoundSink : SoundBase
	{

		public bool listenerflag = true;
		private FMOD.VECTOR up;

		public FMOD.VECTOR previousLocation = new FMOD.VECTOR();
		

		public SoundSink ()
		{
			previousLocation = new VECTOR();
			FMOD.VECTOR up = new FMOD.VECTOR();
			up.x = 0.0f;
			up.y = 1.0f;
			up.z = 0.0f;
		}

		public void update(PointF point, PointF orjentation)
		{
			FMOD.VECTOR pos = new FMOD.VECTOR();
			pos.x = point.X * DISTANCEFACTOR;
			pos.z = point.Y * DISTANCEFACTOR;
			pos.y = 0.0f;

			FMOD.VECTOR forward = new FMOD.VECTOR();
			forward.x = orjentation.X;
			forward.y = 0.0f;
			forward.z = orjentation.Y;

			FMOD.VECTOR vel = new FMOD.VECTOR();

			// ********* NOTE ******* READ NEXT COMMENT!!!!!
			// vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
			vel.x = (pos.x - previousLocation.x) * (1000 / INTERFACE_UPDATETIME);
			vel.y = (pos.y - previousLocation.y) * (1000 / INTERFACE_UPDATETIME);
			vel.z = (pos.z - previousLocation.z) * (1000 / INTERFACE_UPDATETIME);

			// store pos for next time
			previousLocation = pos;

			result = system.set3DListenerAttributes(0, ref pos, ref vel, ref forward, ref up);
			ERRCHECK(result);

			t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example

			if (system != null)
			{
				system.update();
			}
		}
	}
}
